//
//  CoolUtil.h
//  CoolFramework
//
//  Created by xue fei on 11-9-14.
//  Copyright 2011年 FelixApp. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "CoolDevice.h"

@interface CoolUtil : NSObject 

//截图
+ (UIImage *)snapImageOfView:(UIView*)aView;

//将字节数转换成mb单位的字符串
+ (NSString *)mbStringForSize:(double)size;

//将字节数转换成kb单位的字符串
+ (NSString *)kbStringForSize:(double)size;

////去掉http网址部分，返回后面的路径字符串
//+ (NSString*)pathForUrl:(NSURL*)url;
//
//更改图片尺寸
+ (UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize scale:(CGFloat)scale;

//更改图片尺寸
+ (UIImage *)reSizeImage:(UIImage *)image aspectToFitSize:(CGSize)reSize scale:(CGFloat)scale;
//
////更改图片尺寸并且截取指定大小的图片
//+ (UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize cropToSize:(CGSize)croppedSize;
//
////切割图片为指定尺寸
//+ (UIImage *)clipImage:(UIImage *)originalImage toRect:(CGRect)cropRect;

//传入一个相对路径,返回在Library/Caches下的绝对路径,如"xxxxx/Library/Caches/pathComponent"
+ (NSString *)cachesPathByAppendingPathComponent:(NSString *)pathComponent;

//返回bundle中图片的路径,返回的文件名会自动适配retina屏幕
+ (NSString *)pathForImageName:(NSString*)imageName ofType:(NSString *)type inBundle:(NSBundle *)bundle;

//将字符串转换成NSDate对象
+ (NSDate *)dateFromString:(NSString*)dateString withFormat:(NSString *)format;

//将NSDate对象转换成字符串
+ (NSString *)stringFromDate:(NSDate*)date inFormat:(NSString *)format;

////返回当前的viewController, 如果同步调用返回nil, 请在下一个runloop(可以使用- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay)中再调用此方法获得presentedViewController
//+ (UIViewController*)presentedViewController;
//+ (void)setRootViewController:(UIViewController*)rootViewController;
//+ (UIViewController*)rootViewController;

//将xml转义字符转换成原来的字符,譬如&quot;转成\"
+ (NSString *)stringByRecoverXMLEscapesOfString:(NSString *)stringContainEscapes;

//返回subString在string中出现的次数
+ (NSUInteger)numberOfOccurrencesOfSubString:(NSString *)subString options:(NSStringCompareOptions)mask inString:(NSString *)string;

//返回str的MD5
+ (NSString *)md5ForString:(NSString *)str;

//返回base64编码过的字符串
+ (NSString *)base64forData:(NSData *)theData;

//将数组中的每一项用seperator连接成一个字符串
+ (NSString *)connectStringFromArray:(NSArray *)stringArray usingSeperator:(NSString *)seperator;

//返回指定日期所在周的第一天的NSDate对象
+ (NSDate *)firstWeekdayDateOfDate:(NSDate *)date;

//根据字体文件路径获取UIFont对象
+ (UIFont *)fontWithURL:(NSURL *)url size:(CGFloat)size;

//获取Bundle中的字体对象，bundle对象为nil时使用默认bundle
+ (UIFont *)fontWithName:(NSString*)fileName ofType:(NSString *)type size:(CGFloat)size bundle:(NSBundle *)bundleOrNil;

+ (NSString *)URLEncode:(NSString *)unencodedString;

+ (NSString *)URLDecode:(NSString *)encodedString;

+ (CGFloat)contentHeighOfTextView:(UITextView *)textView;

+ (CGFloat)contentHeighOfLabel:(UILabel *)label;

+(CGSize)attributedTextSizeOfLabel:(UILabel *)label;

+ (CGSize)sizeOfMultiLineLabelText:(NSString *)aLabelTextString font:(UIFont *)aLabelFont constrainedToSize:(CGSize)maxSize lineSpacing:(CGFloat)lineSpacing;

+ (NSMutableAttributedString *)contentSpaceLine:(NSString *)content lineSpace:(CGFloat)lineSpacing;
+ (NSMutableAttributedString *)contentSpaceLine:(NSString *)content firstSpace:(CGFloat)firstSpace lineSpace:(CGFloat)lineSpacing;

+ (NSMutableAttributedString *)contentImageSpaceLine:(NSString *)content image:(UIImage *)image  imageFrame:(CGRect)frame lineSpace:(CGFloat)lineSpacing;

+ (NSMutableAttributedString *)contentSpaceLine:(NSString *)content lineSpace:(CGFloat)lineSpacing alignment:(NSTextAlignment)alignment font:(UIFont *)font;

/**
 * 设置富文本
 *
 * @param content       文本内容
 * @param lineSpacing   行间距
 * @param alignment     文本对齐方式
 * @param font          字体大小
 * @param useUnderLine  是否需要下划线
 */

+ (NSMutableAttributedString *)contentSpaceLine:(NSString *)content lineSpace:(CGFloat)lineSpacing alignment:(NSTextAlignment)alignment font:(UIFont *)font useUnderLineStyle:(BOOL)useUnderLine;

+ (NSMutableAttributedString *)contentSpaceLine:(NSString *)content lineSpace:(CGFloat)lineSpacing alignment:(NSTextAlignment)alignment font:(UIFont *)font rangeString:(NSString *)rangeString tintColor:(UIColor *)color;

+ (NSMutableAttributedString *)contentSpaceLine:(NSString *)content lineSpace:(CGFloat)lineSpacing alignment:(NSTextAlignment)alignment font:(UIFont *)font rangeStringArray:(NSArray *)rangeStringArray tintColor:(UIColor *)color;

+ (NSMutableAttributedString *)contentSpaceLine:(NSString *)content lineSpace:(CGFloat)lineSpacing alignment:(NSTextAlignment)alignment font:(UIFont *)font rangeArray:(NSArray *)rangeArray tintColor:(UIColor *)color;

+ (NSString *)formatterText:(NSString *)text;

+ (NSString *)formatterText:(NSString *)text withDefaultText:(NSString *)defaultText;

+ (NSUInteger)formatterType:(NSString *)type;


//返回 通用视图
+ (UILabel *)creatNormalLabel:(UIColor *)textColor align:(NSTextAlignment)textAlignment font:(UIFont *)textFont parent:(UIView *)superView;

+ (UIButton *)createButton:(NSString *)title titleFont:(UIFont *)font titleColor:(UIColor *)tlColor img:(UIImage *)img bg:(UIImage *)bgImg parent:(UIView *)superView;

//返回 分割线 label
+ (UIView *)creatTableSeparatorLineParent:(UIView *)superView;

+ (UIImage *)clipImage:(UIImage *)originalImage toRect:(CGRect)cropRect;

@end
